home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Macintosh Tracker 1.1 Source / Tracker Client Folder / CMyDocument.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-01  |  52.0 KB  |  2,218 lines  |  [TEXT/KAHL]

  1. /* CMyDocument.c */
  2.  
  3. #define compilingmydocument_c
  4.  
  5. #include "CMyDocument.h"
  6. #include "MenuController.h"
  7. #include "CSaveBeforeClosing.h"
  8. #include "Memory.h"
  9. #include "CApplication.h"
  10. #include "File.h"
  11. #include "CSack.h"
  12. #include "Alert.h"
  13. #include "CArray.h"
  14. #include "PortableFile.h"
  15. #include "Error.h"
  16. #include "StandardFile.h"
  17. #include <Sound.h>
  18. #include "CSongList.h"
  19. #include "CRewindButton.h"
  20. #include "CFastForwardButton.h"
  21. #include "CStopButton.h"
  22. #include "CPlayButton.h"
  23. #include "CPauseButton.h"
  24. #include "CSkipToNextButton.h"
  25. #include "LocationConstants.h"
  26. #include "CStaticText.h"
  27. #include "StringUtils.h"
  28. #include "CCheckbox.h"
  29. #include "CNumberEdit.h"
  30. #include "CDefaultStereoOn.h"
  31. #include "CDefaultAntiAlias.h"
  32. #include "CDefaultSamplingRate.h"
  33. #include "CDefaultStereoMix.h"
  34. #include "CDefaultNumRepeats.h"
  35. #include "CDefaultSpeed.h"
  36. #include "CSpecificStereoOn.h"
  37. #include "CSpecificAntiAlias.h"
  38. #include "CSpecificSamplingRate.h"
  39. #include "CSpecificStereoMix.h"
  40. #include "CSpecificNumRepeats.h"
  41. #include "CSpecificSpeed.h"
  42. #include "COverrideStereoOn.h"
  43. #include "COverrideAntiAlias.h"
  44. #include "COverrideSamplingRate.h"
  45. #include "COverrideStereoMix.h"
  46. #include "COverrideNumRepeats.h"
  47. #include "COverrideSpeed.h"
  48. #include "CDividerLine.h"
  49. #include "CMyApplication.h"
  50. #include "CSpecificVolume.h"
  51. #include "CDefaultVolume.h"
  52. #include "COverrideVolume.h"
  53. #include "CAutoNextSong.h"
  54. #include "CRepeat.h"
  55. #include "CAutoStartSongs.h"
  56. #include "CRandomize.h"
  57. #include "CSpecificTracker.h"
  58. #include "CNumOutputBits.h"
  59.  
  60.  
  61. #define UntitledStringID (6592L*65536L + 1)
  62. #define SeparatorID (6592L*65536L + 2)
  63. #define EVENTDELAY (15)
  64.  
  65. #define CouldntSaveSongID (5120L*65536L + 1)
  66. #define ErrorOccurredWhileLoadingID (5120L*65536L + 2)
  67.  
  68. #define MAXRANDOMTRIESBEFOREGIVINGUP (50)
  69.  
  70.  
  71. /* */                CMyDocument::CMyDocument()
  72.     {
  73.         CArray*                SongTemp;
  74.         Handle                Temp;
  75.  
  76.         SongTemp = new CArray;
  77.         SongTemp->IArray(sizeof(SongRec),16);
  78.         ListOfSongs = SongTemp;
  79.  
  80.         RootWindow = NIL;
  81.         EverSaved = False;
  82.         UpToDate = True;
  83.         FileOpenFlag = False;
  84.  
  85.         SamplingRate = 22254;
  86.         StereoOn = False;
  87.         StereoMix = 0;
  88.         AntiAliasing = True;
  89.         Speed = 50;
  90.         NumRepeats = 1;
  91.         Volume = 48;
  92.         AutoNextSong = True;
  93.         Repeat = False;
  94.         AutoStartSongs = True;
  95.         Randomize = False;
  96.         UseSixteenBitMode = False;
  97.  
  98.         Selection = -1;
  99.  
  100.         SongToStart = -1;
  101.         PlayerExists = False;
  102.         PlayNextWhenThisOneStops = False;
  103.         Playing = -1;
  104.  
  105.         GetDateTime((void*)&randSeed);
  106.  
  107.         Temp = GetCString(UntitledStringID);
  108.         Handle2PString(Temp,TheFile.name);
  109.         ReleaseHandle(Temp);
  110.     }
  111.  
  112.  
  113. /* */                CMyDocument::~CMyDocument()
  114.     {
  115.         long                Scan;
  116.         SongRec            Thang;
  117.  
  118.         DeregisterIdler(this);
  119.  
  120.         if (RootWindow != NIL)
  121.             {
  122.                 delete RootWindow;
  123.             }
  124.  
  125.         for (Scan = 0; Scan < ListOfSongs->GetNumElements(); Scan += 1)
  126.             {
  127.                 ListOfSongs->GetElement(Scan,&Thang);
  128.                 ReleaseHandle((Handle)Thang.SongLocation);
  129.             }
  130.         delete ListOfSongs;
  131.  
  132.         if (FileOpenFlag)
  133.             {
  134.                 FCloseFile(FileRef);
  135.             }
  136.     }
  137.  
  138.  
  139. void                CMyDocument::DoNewFile(void)
  140.     {
  141.         MakeNewWindow();
  142.     }
  143.  
  144.  
  145. MyBoolean        CMyDocument::GoAway(void)
  146.     {
  147.         if (!UpToDate && EverSaved)
  148.             {
  149.                 CSaveBeforeClosingWindow*        Saver;
  150.                 MyBoolean                                        Result;
  151.  
  152.                 Saver = new CSaveBeforeClosingWindow;
  153.                 HLock((Handle)this);
  154.                 Result = Saver->SaveBeforeClosing(TheFile.name);
  155.                 HUnlock((Handle)this);
  156.                 switch (Result)
  157.                     {
  158.                         case Yes_Save:
  159.                             if (!SaveFile())
  160.                                 {
  161.                                     return False;
  162.                                 }
  163.                             break;
  164.                         case No_Save:
  165.                             break;
  166.                         case Cancel_Close:
  167.                             return False;
  168.                     }
  169.             }
  170.  
  171.         if (PlayerExists)
  172.             {
  173.                 Application->KillPlayer(OurPlayer);
  174.             }
  175.  
  176.         delete this;
  177.         return True;
  178.     }
  179.  
  180.  
  181. void                CMyDocument::DoPrint(void)
  182.     {
  183.     }
  184.  
  185.  
  186. void                CMyDocument::DoOpenFile(FSSpec* TheSpec)
  187.     {
  188.         short                    LocalRef;
  189.         ulong                    SongCount;
  190.  
  191.         /* reading in all them alias records */
  192.         TheFile = *TheSpec;
  193.         if (FOpenFile(TheSpec,&LocalRef) != noErr)
  194.             {
  195.                 /* error */
  196.             }
  197.         FileOpenFlag = True;
  198.         FileRef = LocalRef;
  199.  
  200.         ResetErrorCheck();
  201.         SamplingRate = (ushort)RShort(LocalRef);
  202.         StereoOn = RChar(LocalRef);
  203.         StereoMix = RShort(LocalRef);
  204.         AntiAliasing = RChar(LocalRef);
  205.         Speed = RShort(LocalRef);
  206.         NumRepeats = RShort(LocalRef);
  207.         Volume = RShort(LocalRef);
  208.         AutoNextSong = RChar(LocalRef);
  209.         Repeat = RChar(LocalRef);
  210.         AutoStartSongs = RChar(LocalRef);
  211.         Randomize = RChar(LocalRef);
  212.  
  213.         SongCount = RShort(LocalRef);
  214.         while (SongCount > 0)
  215.             {
  216.                 ulong                        AliasLength;
  217.                 SongRec                    DaAlias;
  218.                 long                        NewEntry;
  219.  
  220.                 DaAlias.SamplingRateOverrideDefault = RChar(LocalRef);
  221.                 DaAlias.SamplingRate = (ushort)RShort(LocalRef);
  222.                 DaAlias.StereoOnOverrideDefault = RChar(LocalRef);
  223.                 DaAlias.StereoOn = RShort(LocalRef);
  224.                 DaAlias.StereoMixOverrideDefault = RChar(LocalRef);
  225.                 DaAlias.StereoMix = RShort(LocalRef);
  226.                 DaAlias.AntiAliasingOverrideDefault = RChar(LocalRef);
  227.                 DaAlias.AntiAliasing = RShort(LocalRef);
  228.                 DaAlias.SpeedOverrideDefault = RChar(LocalRef);
  229.                 DaAlias.Speed = RShort(LocalRef);
  230.                 DaAlias.NumRepeatsOverrideDefault = RChar(LocalRef);
  231.                 DaAlias.NumRepeats = RShort(LocalRef);
  232.                 DaAlias.VolumeOverrideDefault = RChar(LocalRef);
  233.                 DaAlias.Volume = RShort(LocalRef);
  234.                 DaAlias.Tracker = RChar(LocalRef);
  235.                 FReadBlock(LocalRef,(char*)DaAlias.SongName,SongNameLength);
  236.                 AliasLength = RLong(LocalRef);
  237.                 DaAlias.SongLocation = (AliasRecord**)AllocHandle(AliasLength);
  238.                 HLock((Handle)DaAlias.SongLocation);
  239.                 FReadBlock(LocalRef,(char*)*DaAlias.SongLocation,AliasLength);
  240.                 HUnlock((Handle)DaAlias.SongLocation);
  241.                 DaAlias.PlayedFlag = False;
  242.                 NewEntry = ListOfSongs->AppendElement();
  243.                 ListOfSongs->PutElement(NewEntry,&DaAlias);
  244.                 SongCount -= 1;
  245.             }
  246.         if (ErrorOccurred())
  247.             {
  248.                 AlertError(ErrorOccurredWhileLoadingID,NIL);
  249.             }
  250.         MakeNewWindow();
  251.         SongList->RecalculateScrollBars();
  252.         if ((LastModifiers & controlKey) == 0)
  253.             {
  254.                 /* if they were NOT holding down the control key, then we want */
  255.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  256.                 RelinquishCPU();
  257.             }
  258.         if (AutoStartSongs && ((LastModifiers & controlKey) == 0))
  259.             {
  260.                 /* if they want to autostart songs upon opening the document AND */
  261.                 /* they didn't hold down the command key while selecting "open" */
  262.                 /* (or starting the program) then we can do it. */
  263.                 if (Randomize)
  264.                     {
  265.                         StartRandomSong();
  266.                     }
  267.                  else
  268.                     {
  269.                         StartThisSong(0);
  270.                     }
  271.             }
  272.         EverSaved = True;
  273.     }
  274.  
  275.  
  276. MyBoolean        CMyDocument::SaveFile(void)
  277.     {
  278.         if (EverSaved)
  279.             {
  280.                 WriteData();
  281.                 return True;
  282.             }
  283.          else
  284.             {
  285.                 return SaveFileAs();
  286.             }
  287.     }
  288.  
  289.  
  290. MyBoolean        CMyDocument::SaveFileAs(void)
  291.     {
  292.         FSSpec            NewInfo;
  293.         MyBoolean        Result;
  294.         MyBoolean        Replacing;
  295.  
  296.         HLock((Handle)this);
  297.         Result = FPutFile(TheFile.name,&NewInfo,&Replacing);
  298.         if (Result)
  299.             {
  300.                 if (Replacing)
  301.                     {
  302.                         FDeleteFile(&NewInfo);
  303.                     }
  304.                 TheFile = NewInfo;
  305.                 FCreate(&NewInfo,CREATORCODE,FILETYPE1);
  306.                 FOpenFile(&NewInfo,&FileRef);
  307.                 FileOpenFlag = True;
  308.                 WriteData();
  309.                 EverSaved = True;
  310.                 SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  311.             }
  312.         HUnlock((Handle)this);
  313.         return Result;
  314.     }
  315.  
  316.  
  317. void                CMyDocument::WriteData(void)
  318.     {
  319.         ulong                    SongCount;
  320.         ulong                    SongScan;
  321.         long                    FilePosTemp;
  322.  
  323.         ERROR(!FileOpenFlag,PRERR(ForceAbort,"CMyDocument::WriteData called when "
  324.             "no file was open for writing."));
  325.  
  326.         SpecificSamplingRateBox->StoreValue();
  327.         SpecificStereoMixBox->StoreValue();
  328.         SpecificNumRepeatsBox->StoreValue();
  329.         SpecificSpeedBox->StoreValue();
  330.         SpecificVolumeBox->StoreValue();
  331.         DefaultSamplingRateBox->StoreValue();
  332.         DefaultStereoMixBox->StoreValue();
  333.         DefaultNumRepeatsBox->StoreValue();
  334.         DefaultSpeedBox->StoreValue();
  335.         DefaultVolumeBox->StoreValue();
  336.  
  337.         ResetErrorCheck();
  338.         FSetFilePos(FileRef,0);
  339.  
  340.         WShort(FileRef,SamplingRate);
  341.         WChar(FileRef,StereoOn);
  342.         WShort(FileRef,StereoMix);
  343.         WChar(FileRef,AntiAliasing);
  344.         WShort(FileRef,Speed);
  345.         WShort(FileRef,NumRepeats);
  346.         WShort(FileRef,Volume);
  347.         WChar(FileRef,AutoNextSong);
  348.         WChar(FileRef,Repeat);
  349.         WChar(FileRef,AutoStartSongs);
  350.         WChar(FileRef,Randomize);
  351.  
  352.         SongCount = ListOfSongs->GetNumElements();
  353.         WShort(FileRef,SongCount);
  354.         for (SongScan = 0; SongScan < SongCount; SongScan += 1)
  355.             {
  356.                 SongRec            Song;
  357.                 ulong                AliasSize;
  358.  
  359.                 ListOfSongs->GetElement(SongScan,&Song);
  360.                 WChar(FileRef,Song.SamplingRateOverrideDefault);
  361.                 WShort(FileRef,Song.SamplingRate);
  362.                 WChar(FileRef,Song.StereoOnOverrideDefault);
  363.                 WShort(FileRef,Song.StereoOn);
  364.                 WChar(FileRef,Song.StereoMixOverrideDefault);
  365.                 WShort(FileRef,Song.StereoMix);
  366.                 WChar(FileRef,Song.AntiAliasingOverrideDefault);
  367.                 WShort(FileRef,Song.AntiAliasing);
  368.                 WChar(FileRef,Song.SpeedOverrideDefault);
  369.                 WShort(FileRef,Song.Speed);
  370.                 WChar(FileRef,Song.NumRepeatsOverrideDefault);
  371.                 WShort(FileRef,Song.NumRepeats);
  372.                 WChar(FileRef,Song.VolumeOverrideDefault);
  373.                 WShort(FileRef,Song.Volume);
  374.                 WChar(FileRef,Song.Tracker);
  375.                 FWriteBlock(FileRef,(char*)Song.SongName,SongNameLength);
  376.                 AliasSize = HandleSize((Handle)Song.SongLocation);
  377.                 WLong(FileRef,AliasSize);
  378.                 HLock((Handle)Song.SongLocation);
  379.                 FWriteBlock(FileRef,(char*)*Song.SongLocation,AliasSize);
  380.                 HUnlock((Handle)Song.SongLocation);
  381.             }
  382.         FGetFilePos(FileRef,&FilePosTemp);
  383.         FSetEOF(FileRef,FilePosTemp);
  384.         if (ErrorOccurred())
  385.             {
  386.                 AlertError(CouldntSaveSongID,NIL);
  387.             }
  388.          else
  389.             {
  390.                 UpToDate = True;
  391.             }
  392.     }
  393.  
  394.  
  395. void                CMyDocument::AddSong(FSSpec* TheSpec)
  396.     {
  397.         AliasRecord**            SystemAlias;
  398.         SongRec                        MyAlias;
  399.         long                            IndexToStoreAt;
  400.         OSErr                            Error;
  401.         short                            Scan;
  402.  
  403.         for (Scan = 0; Scan < sizeof(MyAlias); Scan += 1)
  404.             {
  405.                 ((char*)&MyAlias)[Scan] = 0;
  406.             }
  407.         MyAlias.SamplingRateOverrideDefault = False;
  408.         MyAlias.StereoOnOverrideDefault = False;
  409.         MyAlias.StereoMixOverrideDefault = False;
  410.         MyAlias.AntiAliasingOverrideDefault = False;
  411.         MyAlias.SpeedOverrideDefault = False;
  412.         MyAlias.NumRepeatsOverrideDefault = False;
  413.         MyAlias.VolumeOverrideDefault = False;
  414.         MyAlias.SamplingRate = SamplingRate;
  415.         MyAlias.StereoOn = StereoOn;
  416.         MyAlias.StereoMix = StereoMix;
  417.         MyAlias.AntiAliasing = AntiAliasing;
  418.         MyAlias.Speed = Speed;
  419.         MyAlias.NumRepeats = NumRepeats;
  420.         MyAlias.Volume = Volume;
  421.         MyAlias.Tracker = False;
  422.         MemCpy((char*)MyAlias.SongName,(char*)TheSpec->name,TheSpec->name[0] + 1);
  423.         if (MyAlias.SongName[0] > SongNameLength - 1)
  424.             {
  425.                 MyAlias.SongName[0] = SongNameLength - 1;
  426.             }
  427.         Error = NewAlias(NIL,TheSpec,&SystemAlias);
  428.         MyAlias.SongLocation = (AliasRecord**)DupSysHandle((Handle)SystemAlias);
  429.         DisposHandle((Handle)SystemAlias);
  430.         MyAlias.PlayedFlag = False;
  431.         IndexToStoreAt = ListOfSongs->AppendElement();
  432.         ListOfSongs->PutElement(IndexToStoreAt,&MyAlias);
  433.         EXECUTE(ListOfSongs->GetElement(IndexToStoreAt,&MyAlias);)
  434.         SongList->Redraw(IndexToStoreAt,IndexToStoreAt);
  435.         SongList->RecalculateScrollBars();
  436.         if ((LastModifiers & controlKey) == 0)
  437.             {
  438.                 /* if they were NOT holding down the control key, then we want */
  439.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  440.                 RelinquishCPU();
  441.             }
  442.         if ((Playing == -1) && (SongToStart == -1) && AutoStartSongs
  443.             && ((LastModifiers & controlKey) == 0))
  444.             {
  445.                 StartThisSong(IndexToStoreAt);
  446.             }
  447.         UpToDate = False;
  448.     }
  449.  
  450.  
  451. void                CMyDocument::CancelCurrentSong(void)
  452.     {
  453.         if (PlayerExists)
  454.             {
  455.                 Application->KillPlayer(OurPlayer);
  456.                 PlayerState = PlayerDying;
  457.             }
  458.         PlayNextWhenThisOneStops = False;
  459.     }
  460.  
  461.  
  462. void                CMyDocument::StartThisSong(long SongIndex)
  463.     {
  464.         SongRec                    Temp;
  465.  
  466.         if (Playing != -1)
  467.             {
  468.                 CancelCurrentSong();
  469.             }
  470.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  471.             {
  472.                 RegisterIdler(this,EVENTDELAY);
  473.                 SongToStart = SongIndex;
  474.                 ListOfSongs->GetElement(SongIndex,&Temp);
  475.                 Temp.PlayedFlag = True;
  476.                 ListOfSongs->PutElement(SongIndex,&Temp);
  477.             }
  478.         PlayNextWhenThisOneStops = AutoNextSong;
  479.     }
  480.  
  481.  
  482. void                CMyDocument::RemoveSongFromList(long SongIndex)
  483.     {
  484.         SongRec                Temp;
  485.  
  486.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  487.             {
  488.                 if (SongIndex == Playing)
  489.                     {
  490.                         CancelCurrentSong();
  491.                     }
  492.                 if (SongIndex < Playing)
  493.                     {
  494.                         Playing -= 1;
  495.                     }
  496.                 UpToDate = False;
  497.                 ListOfSongs->GetElement(SongIndex,&Temp);
  498.                 ReleaseHandle((Handle)Temp.SongLocation);
  499.                 ListOfSongs->DeleteElement(SongIndex);
  500.                 SongList->Redraw(SongIndex,ListOfSongs->GetNumElements());
  501.             }
  502.     }
  503.  
  504.  
  505. void                CMyDocument::MakeNewWindow(void)
  506.     {
  507.         CWindow*                        Window;
  508.         LongPoint                        Start;
  509.         LongPoint                        Extent;
  510.         CStaticText*                StaticText;
  511.         CPlayButton*                PlayButton;
  512.         CDividerLine*                DividerLine;
  513.  
  514.  
  515.         MoveHHi((Handle)this);
  516.         HLock((Handle)this);
  517.  
  518.  
  519.         Window = new CWindow;
  520.         GetRect(WindowLocsID,&Start,&Extent);
  521.         Start = CenterRect(Extent,MainScreenSize());
  522.         Window->IWindow(Start,Extent,ModelessWindow,NoGrowable,NoZoomable);
  523.         RootWindow = Window;
  524.         SetWTitle(Window->MyGrafPtr,TheFile.name);
  525.  
  526.  
  527.         SongList = new CSongList;
  528.         SongList->ISongList(this,Window);
  529.  
  530.  
  531.         RewindButton = new CRewindButton;
  532.         RewindButton->IRewindButton(this,Window);
  533.  
  534.         StopButton = new CStopButton;
  535.         StopButton->IStopButton(this,Window);
  536.  
  537.         PlayButton = new CPlayButton;
  538.         PlayButton->IPlayButton(this,Window);
  539.         PausePlayButton = PlayButton;
  540.  
  541.         FastForwardButton = new CFastForwardButton;
  542.         FastForwardButton->IFastForwardButton(this,Window);
  543.  
  544.         SkipToNextButton = new CSkipToNextButton;
  545.         SkipToNextButton->ISkipToNextButton(this,Window);
  546.  
  547.  
  548.         StaticText = new CStaticText;
  549.         GetRect(DefaultSettingsID,&Start,&Extent);
  550.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSettingsID),
  551.             applFont,9,Window,Window,JustifyLeft);
  552.  
  553.         StaticText = new CStaticText;
  554.         GetRect(DefaultFrequencyID,&Start,&Extent);
  555.         StaticText->IStaticText(Start,Extent,GetCString(DefaultFrequencyID),
  556.             applFont,9,Window,Window,JustifyLeft);
  557.  
  558.         StaticText = new CStaticText;
  559.         GetRect(DefaultSpeedID,&Start,&Extent);
  560.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSpeedID),
  561.             applFont,9,Window,Window,JustifyLeft);
  562.  
  563.         StaticText = new CStaticText;
  564.         GetRect(DefaultRepeatsID,&Start,&Extent);
  565.         StaticText->IStaticText(Start,Extent,GetCString(DefaultRepeatsID),
  566.             applFont,9,Window,Window,JustifyLeft);
  567.  
  568.         StaticText = new CStaticText;
  569.         GetRect(DefaultMixID,&Start,&Extent);
  570.         StaticText->IStaticText(Start,Extent,GetCString(DefaultMixID),
  571.             applFont,9,Window,Window,JustifyLeft);
  572.  
  573.         StaticText = new CStaticText;
  574.         GetRect(DefaultVolumeID,&Start,&Extent);
  575.         StaticText->IStaticText(Start,Extent,GetCString(DefaultVolumeID),
  576.             applFont,9,Window,Window,JustifyLeft);
  577.  
  578.         SpecificSamplingRateText = new CStaticText;
  579.         GetRect(SpecificFrequencyID,&Start,&Extent);
  580.         SpecificSamplingRateText->IStaticText(Start,Extent,GetCString(SpecificFrequencyID),
  581.             applFont,9,Window,Window,JustifyLeft);
  582.  
  583.         SpecificSpeedText = new CStaticText;
  584.         GetRect(SpecificSpeedID,&Start,&Extent);
  585.         SpecificSpeedText->IStaticText(Start,Extent,GetCString(SpecificSpeedID),
  586.             applFont,9,Window,Window,JustifyLeft);
  587.  
  588.         SpecificNumRepeatsText = new CStaticText;
  589.         GetRect(SpecificRepeatsID,&Start,&Extent);
  590.         SpecificNumRepeatsText->IStaticText(Start,Extent,GetCString(SpecificRepeatsID),
  591.             applFont,9,Window,Window,JustifyLeft);
  592.  
  593.         SpecificStereoMixText = new CStaticText;
  594.         GetRect(SpecificMixID,&Start,&Extent);
  595.         SpecificStereoMixText->IStaticText(Start,Extent,GetCString(SpecificMixID),
  596.             applFont,9,Window,Window,JustifyLeft);
  597.  
  598.         SpecificVolumeText = new CStaticText;
  599.         GetRect(SpecificVolumeID,&Start,&Extent);
  600.         SpecificVolumeText->IStaticText(Start,Extent,GetCString(SpecificVolumeID),
  601.             applFont,9,Window,Window,JustifyLeft);
  602.  
  603.         AutoNextSongBox = new CAutoNextSong;
  604.         AutoNextSongBox->IAutoNextSong(this,Window);
  605.  
  606.         RepeatBox = new CRepeat;
  607.         RepeatBox->IRepeat(this,Window);
  608.  
  609.         AutoStartSongsBox = new CAutoStartSongs;
  610.         AutoStartSongsBox->IAutoStartSongs(this,Window);
  611.  
  612.         RandomizeBox = new CRandomize;
  613.         RandomizeBox->IRandomize(this,Window);
  614.  
  615.         DividerLine = new CDividerLine;
  616.         DividerLine->IDividerLine(Window);
  617.  
  618.  
  619.         DefaultStereoOnBox = new CDefaultStereoOn;
  620.         DefaultStereoOnBox->IDefaultStereoOn(this,Window);
  621.  
  622.         DefaultAntiAliasingBox = new CDefaultAntiAliasing;
  623.         DefaultAntiAliasingBox->IDefaultAntiAliasing(this,Window);
  624.  
  625.         DefaultVolumeBox = new CDefaultVolume;
  626.         DefaultVolumeBox->IDefaultVolume(this,Window);
  627.         DefaultVolumeBox->SetValue(Volume);
  628.  
  629.         DefaultSamplingRateBox = new CDefaultSamplingRate;
  630.         DefaultSamplingRateBox->IDefaultSamplingRate(this,Window);
  631.         DefaultSamplingRateBox->SetValue(SamplingRate);
  632.  
  633.         DefaultSpeedBox = new CDefaultSpeed;
  634.         DefaultSpeedBox->IDefaultSpeed(this,Window);
  635.         DefaultSpeedBox->SetValue(Speed);
  636.  
  637.         DefaultNumRepeatsBox = new CDefaultNumRepeats;
  638.         DefaultNumRepeatsBox->IDefaultNumRepeats(this,Window);
  639.         DefaultNumRepeatsBox->SetValue(NumRepeats);
  640.  
  641.         DefaultStereoMixBox = new CDefaultStereoMix;
  642.         DefaultStereoMixBox->IDefaultStereoMix(this,Window);
  643.         DefaultStereoMixBox->SetValue(StereoMix);
  644.  
  645.         NumOutputBitsBox = new CNumOutputBits;
  646.         NumOutputBitsBox->INumOutputBits(this,Window);
  647.  
  648.  
  649.         SpecificStereoOnBox = new CSpecificStereoOn;
  650.         SpecificStereoOnBox->ISpecificStereoOn(this,Window);
  651.  
  652.         SpecificAntiAliasingBox = new CSpecificAntiAliasing;
  653.         SpecificAntiAliasingBox->ISpecificAntiAliasing(this,Window);
  654.  
  655.         SpecificVolumeBox = new CSpecificVolume;
  656.         SpecificVolumeBox->ISpecificVolume(this,Window);
  657.  
  658.         SpecificSamplingRateBox = new CSpecificSamplingRate;
  659.         SpecificSamplingRateBox->ISpecificSamplingRate(this,Window);
  660.  
  661.         SpecificSpeedBox = new CSpecificSpeed;
  662.         SpecificSpeedBox->ISpecificSpeed(this,Window);
  663.  
  664.         SpecificNumRepeatsBox = new CSpecificNumRepeats;
  665.         SpecificNumRepeatsBox->ISpecificNumRepeats(this,Window);
  666.  
  667.         SpecificStereoMixBox = new CSpecificStereoMix;
  668.         SpecificStereoMixBox->ISpecificStereoMix(this,Window);
  669.  
  670.         SpecificTrackerBox = new CSpecificTracker;
  671.         SpecificTrackerBox->ISpecificTracker(this,Window);
  672.  
  673.  
  674.         OverrideStereoOnBox = new COverrideStereoOn;
  675.         OverrideStereoOnBox->IOverrideStereoOn(this,Window);
  676.  
  677.         OverrideAntiAliasingBox = new COverrideAntiAliasing;
  678.         OverrideAntiAliasingBox->IOverrideAntiAliasing(this,Window);
  679.  
  680.         OverrideSamplingRateBox = new COverrideSamplingRate;
  681.         OverrideSamplingRateBox->IOverrideSamplingRate(this,Window);
  682.  
  683.         OverrideStereoMixBox = new COverrideStereoMix;
  684.         OverrideStereoMixBox->IOverrideStereoMix(this,Window);
  685.  
  686.         OverrideNumRepeatsBox = new COverrideNumRepeats;
  687.         OverrideNumRepeatsBox->IOverrideNumRepeats(this,Window);
  688.  
  689.         OverrideSpeedBox = new COverrideSpeed;
  690.         OverrideSpeedBox->IOverrideSpeed(this,Window);
  691.  
  692.         OverrideVolumeBox = new COverrideVolume;
  693.         OverrideVolumeBox->IOverrideVolume(this,Window);
  694.  
  695.  
  696.         SpecificStereoOnBox->DoDisable();
  697.         SpecificAntiAliasingBox->DoDisable();
  698.         SpecificSamplingRateBox->DoDisable();
  699.         SpecificStereoMixBox->DoDisable();
  700.         SpecificNumRepeatsBox->DoDisable();
  701.         SpecificSpeedBox->DoDisable();
  702.         SpecificVolumeBox->DoDisable();
  703.         SpecificTrackerBox->DoDisable();
  704.         SpecificSamplingRateText->DoDisable();
  705.         SpecificStereoMixText->DoDisable();
  706.         SpecificNumRepeatsText->DoDisable();
  707.         SpecificSpeedText->DoDisable();
  708.         SpecificVolumeText->DoDisable();
  709.  
  710.         OverrideStereoOnBox->DoDisable();
  711.         OverrideAntiAliasingBox->DoDisable();
  712.         OverrideSamplingRateBox->DoDisable();
  713.         OverrideStereoMixBox->DoDisable();
  714.         OverrideNumRepeatsBox->DoDisable();
  715.         OverrideSpeedBox->DoDisable();
  716.         OverrideVolumeBox->DoDisable();
  717.  
  718.         if (StereoOn)
  719.             {
  720.                 DefaultStereoOnBox->DoThang();
  721.             }
  722.  
  723.         if (AntiAliasing)
  724.             {
  725.                 DefaultAntiAliasingBox->DoThang();
  726.             }
  727.  
  728.         if (AutoNextSong)
  729.             {
  730.                 AutoNextSongBox->DoThang();
  731.             }
  732.  
  733.         if (Repeat)
  734.             {
  735.                 RepeatBox->DoThang();
  736.             }
  737.  
  738.         if (AutoStartSongs)
  739.             {
  740.                 AutoStartSongsBox->DoThang();
  741.             }
  742.  
  743.         if (Randomize)
  744.             {
  745.                 RandomizeBox->DoThang();
  746.             }
  747.  
  748.         RewindButton->DoDisable();
  749.         StopButton->DoDisable();
  750.         PausePlayButton->DoEnable();
  751.         FastForwardButton->DoDisable();
  752.         SkipToNextButton->DoDisable();
  753.  
  754.  
  755.         HUnlock((Handle)this);
  756.     }
  757.  
  758.  
  759. void                CMyDocument::SetStereoOn(MyBoolean NewStereoOn)
  760.     {
  761.         SongRec                Temp;
  762.  
  763.         if (Selection == -1)
  764.             {
  765.                 return;
  766.             }
  767.  
  768.         UpToDate = False;
  769.         ListOfSongs->GetElement(Selection,&Temp);
  770.         Temp.StereoOn = NewStereoOn;
  771.         ListOfSongs->PutElement(Selection,&Temp);
  772.         if (SpecificStereoOnBox->State != NewStereoOn)
  773.             {
  774.                 SpecificStereoOnBox->DoThang();
  775.             }
  776.         if (Selection == Playing)
  777.             {
  778.                 SendMessage((short)NewStereoOn,keyStereoOn);
  779.             }
  780.     }
  781.  
  782.  
  783. void                CMyDocument::SetSpecificTracker(MyBoolean UseFrankSeide)
  784.     {
  785.         SongRec                Temp;
  786.  
  787.         if (Selection == -1)
  788.             {
  789.                 return;
  790.             }
  791.  
  792.         UpToDate = False;
  793.         ListOfSongs->GetElement(Selection,&Temp);
  794.         Temp.Tracker = UseFrankSeide;
  795.         ListOfSongs->PutElement(Selection,&Temp);
  796.         if (SpecificTrackerBox->State != UseFrankSeide)
  797.             {
  798.                 SpecificTrackerBox->DoThang();
  799.             }
  800.     }
  801.  
  802.  
  803. void                CMyDocument::SetNumOutputBits(MyBoolean SixteenBitMode)
  804.     {
  805.         UseSixteenBitMode = SixteenBitMode;
  806.         if (NumOutputBitsBox->State != SixteenBitMode)
  807.             {
  808.                 NumOutputBitsBox->DoThang();
  809.             }
  810.     }
  811.  
  812.  
  813. void                CMyDocument::SetAntiAliasing(MyBoolean NewAntiAliasing)
  814.     {
  815.         SongRec                Temp;
  816.  
  817.         if (Selection == -1)
  818.             {
  819.                 return;
  820.             }
  821.  
  822.         UpToDate = False;
  823.         ListOfSongs->GetElement(Selection,&Temp);
  824.         Temp.AntiAliasing = NewAntiAliasing;
  825.         ListOfSongs->PutElement(Selection,&Temp);
  826.         if (SpecificAntiAliasingBox->State != NewAntiAliasing)
  827.             {
  828.                 SpecificAntiAliasingBox->DoThang();
  829.             }
  830.         if (Selection == Playing)
  831.             {
  832.                 SendMessage((short)NewAntiAliasing,keyAntiAliasing);
  833.             }
  834.     }
  835.  
  836.  
  837. void                CMyDocument::SetSamplingRate(ulong NewSamplingRate)
  838.     {
  839.         SongRec                Temp;
  840.  
  841.         if (Selection == -1)
  842.             {
  843.                 return;
  844.             }
  845.  
  846.         UpToDate = False;
  847.         ListOfSongs->GetElement(Selection,&Temp);
  848.         Temp.SamplingRate = NewSamplingRate;
  849.         ListOfSongs->PutElement(Selection,&Temp);
  850.         SpecificSamplingRateBox->SetValue(NewSamplingRate);
  851.         if (Selection == Playing)
  852.             {
  853.                 SendMessage((short)NewSamplingRate,keySamplingRate);
  854.             }
  855.     }
  856.  
  857.  
  858. void                CMyDocument::SetStereoMix(short NewStereoMix)
  859.     {
  860.         SongRec                Temp;
  861.  
  862.         if (Selection == -1)
  863.             {
  864.                 return;
  865.             }
  866.  
  867.         UpToDate = False;
  868.         ListOfSongs->GetElement(Selection,&Temp);
  869.         Temp.StereoMix = NewStereoMix;
  870.         ListOfSongs->PutElement(Selection,&Temp);
  871.         SpecificStereoMixBox->SetValue(NewStereoMix);
  872.         if (Selection == Playing)
  873.             {
  874.                 SendMessage((short)NewStereoMix,keyStereoMix);
  875.             }
  876.     }
  877.  
  878.  
  879. void                CMyDocument::SetNumRepeats(short NewNumRepeats)
  880.     {
  881.         SongRec                Temp;
  882.  
  883.         if (Selection == -1)
  884.             {
  885.                 return;
  886.             }
  887.  
  888.         UpToDate = False;
  889.         ListOfSongs->GetElement(Selection,&Temp);
  890.         Temp.NumRepeats = NewNumRepeats;
  891.         ListOfSongs->PutElement(Selection,&Temp);
  892.         SpecificNumRepeatsBox->SetValue(NewNumRepeats);
  893.         if (Selection == Playing)
  894.             {
  895.                 SendMessage((short)NewNumRepeats,keyNumRepeats);
  896.             }
  897.     }
  898.  
  899.  
  900. void                CMyDocument::SetSpeed(short NewSpeed)
  901.     {
  902.         SongRec                Temp;
  903.  
  904.         if (Selection == -1)
  905.             {
  906.                 return;
  907.             }
  908.  
  909.         UpToDate = False;
  910.         ListOfSongs->GetElement(Selection,&Temp);
  911.         Temp.Speed = NewSpeed;
  912.         ListOfSongs->PutElement(Selection,&Temp);
  913.         SpecificSpeedBox->SetValue(NewSpeed);
  914.         if (Selection == Playing)
  915.             {
  916.                 SendMessage((short)NewSpeed,keySpeed);
  917.             }
  918.     }
  919.  
  920.  
  921. void                CMyDocument::SetVolume(short NewVolume)
  922.     {
  923.         SongRec                Temp;
  924.  
  925.         if (Selection == -1)
  926.             {
  927.                 return;
  928.             }
  929.  
  930.         UpToDate = False;
  931.         ListOfSongs->GetElement(Selection,&Temp);
  932.         Temp.Volume = NewVolume;
  933.         ListOfSongs->PutElement(Selection,&Temp);
  934.         SpecificVolumeBox->SetValue(NewVolume);
  935.         if (Selection == Playing)
  936.             {
  937.                 SendMessage((short)NewVolume,keyLoudness);
  938.             }
  939.     }
  940.  
  941.  
  942. void                CMyDocument::SetOverrideStereoOn(MyBoolean Flag)
  943.     {
  944.         SongRec                Temp;
  945.  
  946.         if (Selection == -1)
  947.             {
  948.                 return;
  949.             }
  950.  
  951.         UpToDate = False;
  952.         ListOfSongs->GetElement(Selection,&Temp);
  953.         Temp.StereoOnOverrideDefault = Flag;
  954.         if (Flag)
  955.             {
  956.                 Temp.StereoOn = StereoOn;
  957.                 SpecificStereoOnBox->DoEnable();
  958.                 if (SpecificStereoOnBox->State != Temp.StereoOn)
  959.                     {
  960.                         SpecificStereoOnBox->DoThang();
  961.                     }
  962.             }
  963.          else
  964.             {
  965.                 SpecificStereoOnBox->DoDisable();
  966.                 if (Selection == Playing)
  967.                     {
  968.                         SendMessage((short)StereoOn,keyStereoOn);
  969.                     }
  970.             }
  971.         ListOfSongs->PutElement(Selection,&Temp);
  972.     }
  973.  
  974.  
  975. void                CMyDocument::SetOverrideAntiAliasing(MyBoolean Flag)
  976.     {
  977.         SongRec                Temp;
  978.  
  979.         if (Selection == -1)
  980.             {
  981.                 return;
  982.             }
  983.  
  984.         UpToDate = False;
  985.         ListOfSongs->GetElement(Selection,&Temp);
  986.         Temp.AntiAliasingOverrideDefault = Flag;
  987.         if (Flag)
  988.             {
  989.                 Temp.AntiAliasing = AntiAliasing;
  990.                 SpecificAntiAliasingBox->DoEnable();
  991.                 if (SpecificAntiAliasingBox->State != Temp.AntiAliasing)
  992.                     {
  993.                         SpecificAntiAliasingBox->DoThang();
  994.                     }
  995.             }
  996.          else
  997.             {
  998.                 SpecificAntiAliasingBox->DoDisable();
  999.                 if (Selection == Playing)
  1000.                     {
  1001.                         SendMessage((short)AntiAliasing,keyAntiAliasing);
  1002.                     }
  1003.             }
  1004.         ListOfSongs->PutElement(Selection,&Temp);
  1005.     }
  1006.  
  1007.  
  1008. void                CMyDocument::SetOverrideSamplingRate(MyBoolean Flag)
  1009.     {
  1010.         SongRec                Temp;
  1011.  
  1012.         if (Selection == -1)
  1013.             {
  1014.                 return;
  1015.             }
  1016.  
  1017.         UpToDate = False;
  1018.         ListOfSongs->GetElement(Selection,&Temp);
  1019.         Temp.SamplingRateOverrideDefault = Flag;
  1020.         if (Flag)
  1021.             {
  1022.                 Temp.SamplingRate = SamplingRate;
  1023.                 SpecificSamplingRateBox->DoEnable();
  1024.                 SpecificSamplingRateText->DoEnable();
  1025.                 if (SpecificSamplingRateBox->GetValue() != Temp.SamplingRate)
  1026.                     {
  1027.                         SpecificSamplingRateBox->SetValue(Temp.SamplingRate);
  1028.                     }
  1029.             }
  1030.          else
  1031.             {
  1032.                 SpecificSamplingRateBox->DoDisable();
  1033.                 SpecificSamplingRateText->DoDisable();
  1034.                 if (Selection == Playing)
  1035.                     {
  1036.                         SendMessage((short)SamplingRate,keySamplingRate);
  1037.                     }
  1038.             }
  1039.         ListOfSongs->PutElement(Selection,&Temp);
  1040.     }
  1041.  
  1042.  
  1043. void                CMyDocument::SetOverrideStereoMix(MyBoolean Flag)
  1044.     {
  1045.         SongRec                Temp;
  1046.  
  1047.         if (Selection == -1)
  1048.             {
  1049.                 return;
  1050.             }
  1051.  
  1052.         UpToDate = False;
  1053.         ListOfSongs->GetElement(Selection,&Temp);
  1054.         Temp.StereoMixOverrideDefault = Flag;
  1055.         if (Flag)
  1056.             {
  1057.                 Temp.StereoMix = StereoMix;
  1058.                 SpecificStereoMixBox->DoEnable();
  1059.                 SpecificStereoMixText->DoEnable();
  1060.                 if (SpecificStereoMixBox->GetValue() != Temp.StereoMix)
  1061.                     {
  1062.                         SpecificStereoMixBox->SetValue(Temp.StereoMix);
  1063.                     }
  1064.             }
  1065.          else
  1066.             {
  1067.                 SpecificStereoMixBox->DoDisable();
  1068.                 SpecificStereoMixText->DoDisable();
  1069.                 if (Selection == Playing)
  1070.                     {
  1071.                         SendMessage((short)StereoMix,keyStereoMix);
  1072.                     }
  1073.             }
  1074.         ListOfSongs->PutElement(Selection,&Temp);
  1075.     }
  1076.  
  1077.  
  1078. void                CMyDocument::SetOverrideNumRepeats(MyBoolean Flag)
  1079.     {
  1080.         SongRec                Temp;
  1081.  
  1082.         if (Selection == -1)
  1083.             {
  1084.                 return;
  1085.             }
  1086.  
  1087.         UpToDate = False;
  1088.         ListOfSongs->GetElement(Selection,&Temp);
  1089.         Temp.NumRepeatsOverrideDefault = Flag;
  1090.         if (Flag)
  1091.             {
  1092.                 Temp.NumRepeats = NumRepeats;
  1093.                 SpecificNumRepeatsBox->DoEnable();
  1094.                 SpecificNumRepeatsText->DoEnable();
  1095.                 if (SpecificNumRepeatsBox->GetValue() != Temp.NumRepeats)
  1096.                     {
  1097.                         SpecificNumRepeatsBox->SetValue(Temp.NumRepeats);
  1098.                     }
  1099.             }
  1100.          else
  1101.             {
  1102.                 SpecificNumRepeatsBox->DoDisable();
  1103.                 SpecificNumRepeatsText->DoDisable();
  1104.                 if (Selection == Playing)
  1105.                     {
  1106.                         SendMessage((short)NumRepeats,keyNumRepeats);
  1107.                     }
  1108.             }
  1109.         ListOfSongs->PutElement(Selection,&Temp);
  1110.     }
  1111.  
  1112.  
  1113. void                CMyDocument::SetOverrideSpeed(MyBoolean Flag)
  1114.     {
  1115.         SongRec                Temp;
  1116.  
  1117.         if (Selection == -1)
  1118.             {
  1119.                 return;
  1120.             }
  1121.  
  1122.         UpToDate = False;
  1123.         ListOfSongs->GetElement(Selection,&Temp);
  1124.         Temp.SpeedOverrideDefault = Flag;
  1125.         if (Flag)
  1126.             {
  1127.                 Temp.Speed = Speed;
  1128.                 SpecificSpeedBox->DoEnable();
  1129.                 SpecificSpeedText->DoEnable();
  1130.                 if (SpecificSpeedBox->GetValue() != Temp.Speed)
  1131.                     {
  1132.                         SpecificSpeedBox->SetValue(Temp.Speed);
  1133.                     }
  1134.             }
  1135.          else
  1136.             {
  1137.                 SpecificSpeedBox->DoDisable();
  1138.                 SpecificSpeedText->DoDisable();
  1139.                 if (Selection == Playing)
  1140.                     {
  1141.                         SendMessage((short)Speed,keySpeed);
  1142.                     }
  1143.             }
  1144.         ListOfSongs->PutElement(Selection,&Temp);
  1145.     }
  1146.  
  1147.  
  1148. void                CMyDocument::SetOverrideVolume(MyBoolean Flag)
  1149.     {
  1150.         SongRec                Temp;
  1151.  
  1152.         if (Selection == -1)
  1153.             {
  1154.                 return;
  1155.             }
  1156.  
  1157.         UpToDate = False;
  1158.         ListOfSongs->GetElement(Selection,&Temp);
  1159.         Temp.VolumeOverrideDefault = Flag;
  1160.         if (Flag)
  1161.             {
  1162.                 Temp.Volume = Volume;
  1163.                 SpecificVolumeBox->DoEnable();
  1164.                 SpecificVolumeText->DoEnable();
  1165.                 if (SpecificVolumeBox->GetValue() != Temp.Volume)
  1166.                     {
  1167.                         SpecificVolumeBox->SetValue(Temp.Volume);
  1168.                     }
  1169.             }
  1170.          else
  1171.             {
  1172.                 SpecificVolumeBox->DoDisable();
  1173.                 SpecificVolumeText->DoDisable();
  1174.                 if (Selection == Playing)
  1175.                     {
  1176.                         SendMessage((short)Volume,keyLoudness);
  1177.                     }
  1178.             }
  1179.         ListOfSongs->PutElement(Selection,&Temp);
  1180.     }
  1181.  
  1182.  
  1183. void                CMyDocument::SetDefaultStereoOn(MyBoolean NewStereoOn)
  1184.     {
  1185.         StereoOn = NewStereoOn;
  1186.         if (DefaultStereoOnBox->State != NewStereoOn)
  1187.             {
  1188.                 DefaultStereoOnBox->DoThang();
  1189.             }
  1190.         if (!OverrideStereoOnBox->State)
  1191.             {
  1192.                 if (SpecificStereoOnBox->State != NewStereoOn)
  1193.                     {
  1194.                         SpecificStereoOnBox->DoThang();
  1195.                     }
  1196.                 if (Selection == Playing)
  1197.                     {
  1198.                         SendMessage((short)NewStereoOn,keyStereoOn);
  1199.                     }
  1200.             }
  1201.         UpToDate = False;
  1202.     }
  1203.  
  1204.  
  1205. void                CMyDocument::SetDefaultAntiAliasing(MyBoolean NewAntiAliasing)
  1206.     {
  1207.         AntiAliasing = NewAntiAliasing;
  1208.         if (DefaultAntiAliasingBox->State != NewAntiAliasing)
  1209.             {
  1210.                 DefaultAntiAliasingBox->DoThang();
  1211.             }
  1212.         if (!OverrideAntiAliasingBox->State)
  1213.             {
  1214.                 if (SpecificAntiAliasingBox->State != NewAntiAliasing)
  1215.                     {
  1216.                         SpecificAntiAliasingBox->DoThang();
  1217.                     }
  1218.                 if (Selection == Playing)
  1219.                     {
  1220.                         SendMessage((short)NewAntiAliasing,keyAntiAliasing);
  1221.                     }
  1222.             }
  1223.         UpToDate = False;
  1224.     }
  1225.  
  1226.  
  1227. void                CMyDocument::SetDefaultSamplingRate(ulong NewSamplingRate)
  1228.     {
  1229.         SamplingRate = NewSamplingRate;
  1230.         if (DefaultSamplingRateBox->GetValue() != NewSamplingRate)
  1231.             {
  1232.                 DefaultSamplingRateBox->SetValue(NewSamplingRate);
  1233.             }
  1234.         if (!OverrideSamplingRateBox->State)
  1235.             {
  1236.                 if (SpecificSamplingRateBox->GetValue() != NewSamplingRate)
  1237.                     {
  1238.                         SpecificSamplingRateBox->SetValue(NewSamplingRate);
  1239.                     }
  1240.                 if (Selection == Playing)
  1241.                     {
  1242.                         SendMessage((short)NewSamplingRate,keySamplingRate);
  1243.                     }
  1244.             }
  1245.         UpToDate = False;
  1246.     }
  1247.  
  1248.  
  1249. void                CMyDocument::SetDefaultStereoMix(short NewStereoMix)
  1250.     {
  1251.         StereoMix = NewStereoMix;
  1252.         if (DefaultStereoMixBox->GetValue() != NewStereoMix)
  1253.             {
  1254.                 DefaultStereoMixBox->SetValue(NewStereoMix);
  1255.             }
  1256.         if (!OverrideStereoMixBox->State)
  1257.             {
  1258.                 if (SpecificStereoMixBox->GetValue() != NewStereoMix)
  1259.                     {
  1260.                         SpecificStereoMixBox->SetValue(NewStereoMix);
  1261.                     }
  1262.                 if (Selection == Playing)
  1263.                     {
  1264.                         SendMessage((short)NewStereoMix,keyStereoMix);
  1265.                     }
  1266.             }
  1267.         UpToDate = False;
  1268.     }
  1269.  
  1270.  
  1271. void                CMyDocument::SetDefaultNumRepeats(short NewNumRepeats)
  1272.     {
  1273.         NumRepeats = NewNumRepeats;
  1274.         if (DefaultNumRepeatsBox->GetValue() != NewNumRepeats)
  1275.             {
  1276.                 DefaultNumRepeatsBox->SetValue(NewNumRepeats);
  1277.             }
  1278.         if (!OverrideNumRepeatsBox->State)
  1279.             {
  1280.                 if (SpecificNumRepeatsBox->GetValue() != NewNumRepeats)
  1281.                     {
  1282.                         SpecificNumRepeatsBox->SetValue(NewNumRepeats);
  1283.                     }
  1284.                 if (Selection == Playing)
  1285.                     {
  1286.                         SendMessage((short)NewNumRepeats,keyNumRepeats);
  1287.                     }
  1288.             }
  1289.         UpToDate = False;
  1290.     }
  1291.  
  1292.  
  1293. void                CMyDocument::SetDefaultSpeed(short NewSpeed)
  1294.     {
  1295.         Speed = NewSpeed;
  1296.         if (DefaultSpeedBox->GetValue() != NewSpeed)
  1297.             {
  1298.                 DefaultSpeedBox->SetValue(NewSpeed);
  1299.             }
  1300.         if (!OverrideSpeedBox->State)
  1301.             {
  1302.                 if (SpecificSpeedBox->GetValue() != NewSpeed)
  1303.                     {
  1304.                         SpecificSpeedBox->SetValue(NewSpeed);
  1305.                     }
  1306.                 if (Selection == Playing)
  1307.                     {
  1308.                         SendMessage((short)NewSpeed,keySpeed);
  1309.                     }
  1310.             }
  1311.         UpToDate = False;
  1312.     }
  1313.  
  1314.  
  1315. void                CMyDocument::SetDefaultVolume(short NewVolume)
  1316.     {
  1317.         Volume = NewVolume;
  1318.         if (DefaultVolumeBox->GetValue() != NewVolume)
  1319.             {
  1320.                 DefaultVolumeBox->SetValue(NewVolume);
  1321.             }
  1322.         if (!OverrideVolumeBox->State)
  1323.             {
  1324.                 if (SpecificVolumeBox->GetValue() != NewVolume)
  1325.                     {
  1326.                         SpecificVolumeBox->SetValue(NewVolume);
  1327.                     }
  1328.                 if (Selection == Playing)
  1329.                     {
  1330.                         SendMessage((short)NewVolume,keyLoudness);
  1331.                     }
  1332.             }
  1333.         UpToDate = False;
  1334.     }
  1335.  
  1336.  
  1337. void                CMyDocument::SetAutoNextSong(MyBoolean NewAutoNextSong)
  1338.     {
  1339.         AutoNextSong = NewAutoNextSong;
  1340.         if (Playing != -1)
  1341.             {
  1342.                 PlayNextWhenThisOneStops = NewAutoNextSong;
  1343.             }
  1344.         if (AutoNextSongBox->State != NewAutoNextSong)
  1345.             {
  1346.                 AutoNextSongBox->DoThang();
  1347.             }
  1348.         UpToDate = False;
  1349.     }
  1350.  
  1351.  
  1352. void                CMyDocument::SetAutoStartSongs(MyBoolean NewAutoStartSongs)
  1353.     {
  1354.         AutoStartSongs = NewAutoStartSongs;
  1355.         if (AutoStartSongsBox->State != NewAutoStartSongs)
  1356.             {
  1357.                 AutoStartSongsBox->DoThang();
  1358.             }
  1359.         UpToDate = False;
  1360.     }
  1361.  
  1362.  
  1363. void                CMyDocument::SetRandomize(MyBoolean NewRandomize)
  1364.     {
  1365.         Randomize = NewRandomize;
  1366.         if (RandomizeBox->State != NewRandomize)
  1367.             {
  1368.                 RandomizeBox->DoThang();
  1369.             }
  1370.         UpToDate = False;
  1371.     }
  1372.  
  1373.  
  1374. void                CMyDocument::SetRepeat(MyBoolean NewRepeat)
  1375.     {
  1376.         Repeat = NewRepeat;
  1377.         if (RepeatBox->State != NewRepeat)
  1378.             {
  1379.                 RepeatBox->DoThang();
  1380.             }
  1381.         UpToDate = False;
  1382.     }
  1383.  
  1384.  
  1385. void                CMyDocument::DoRewind(MyBoolean Flag)
  1386.     {
  1387.         short                SpiffParam;
  1388.  
  1389.         if ((Playing != -1) && PlayerExists)
  1390.             {
  1391.                 if (Flag)
  1392.                     {
  1393.                         SpiffParam = '<';
  1394.                     }
  1395.                  else
  1396.                     {
  1397.                         SpiffParam = '|';
  1398.                     }
  1399.                 SendMessage(SpiffParam,keyKeyPressCharacter);
  1400.             }
  1401.     }
  1402.  
  1403.  
  1404. void                CMyDocument::DoStop(void)
  1405.     {
  1406.         if (Playing != -1)
  1407.             {
  1408.                 CancelCurrentSong();
  1409.             }
  1410.         ResetRandomPlayList();
  1411.         DeregisterIdler(this);
  1412.     }
  1413.  
  1414.  
  1415. void                CMyDocument::DoPlay(void)
  1416.     {
  1417.         SpecificSamplingRateBox->StoreValue();
  1418.         SpecificStereoMixBox->StoreValue();
  1419.         SpecificNumRepeatsBox->StoreValue();
  1420.         SpecificSpeedBox->StoreValue();
  1421.         SpecificVolumeBox->StoreValue();
  1422.         DefaultSamplingRateBox->StoreValue();
  1423.         DefaultStereoMixBox->StoreValue();
  1424.         DefaultNumRepeatsBox->StoreValue();
  1425.         DefaultSpeedBox->StoreValue();
  1426.         DefaultVolumeBox->StoreValue();
  1427.         /* this could either be invoked while playing but paused, or when nothing */
  1428.         /* is playing at all. */
  1429.         if (Playing == -1)
  1430.             {
  1431.                 /* nothing playing; start selected song */
  1432.                 if (Selection != -1)
  1433.                     {
  1434.                         StartThisSong(Selection);
  1435.                     }
  1436.                  else
  1437.                     {
  1438.                         if (Randomize)
  1439.                             {
  1440.                                 StartRandomSong();
  1441.                             }
  1442.                          else
  1443.                             {
  1444.                                 StartThisSong(0);
  1445.                             }
  1446.                     }
  1447.             }
  1448.          else
  1449.             {
  1450.                 CPauseButton*            PauseButton;
  1451.  
  1452.                 /* paused, resume playing */
  1453.                 if (PausePlayButton != NIL)
  1454.                     {
  1455.                         delete PausePlayButton;
  1456.                     }
  1457.                 PauseButton = new CPauseButton;
  1458.                 PausePlayButton = PauseButton;
  1459.                 PauseButton->IPauseButton(this,RootWindow);
  1460.                 if (!RootWindow->Suspended)
  1461.                     {
  1462.                         PauseButton->DoResume();
  1463.                     }
  1464.                 PauseButton->DoUpdate();
  1465.  
  1466.                 /* sending unpause event */
  1467.                 SendMessage(' ',keyKeyPressCharacter);
  1468.             }
  1469.     }
  1470.  
  1471.  
  1472. void                CMyDocument::DoPause(void)
  1473.     {
  1474.         if ((Playing != -1) && PlayerExists)
  1475.             {
  1476.                 CPlayButton*            PlayButton;
  1477.  
  1478.                 /* playing, pause song */
  1479.                 if (PausePlayButton != NIL)
  1480.                     {
  1481.                         delete PausePlayButton;
  1482.                     }
  1483.                 PlayButton = new CPlayButton;
  1484.                 PausePlayButton = PlayButton;
  1485.                 PlayButton->IPlayButton(this,RootWindow);
  1486.                 if (!RootWindow->Suspended)
  1487.                     {
  1488.                         PlayButton->DoResume();
  1489.                     }
  1490.                 PlayButton->DoUpdate();
  1491.  
  1492.                 /* sending pause event */
  1493.                 SendMessage(' ',keyKeyPressCharacter);
  1494.             }
  1495.     }
  1496.  
  1497.  
  1498. void                CMyDocument::DoFastForward(MyBoolean Flag)
  1499.     {
  1500.         short                SpiffParam;
  1501.  
  1502.         if ((Playing != -1) && PlayerExists)
  1503.             {
  1504.                 if (Flag)
  1505.                     {
  1506.                         SpiffParam = '>';
  1507.                     }
  1508.                  else
  1509.                     {
  1510.                         SpiffParam = '|';
  1511.                     }
  1512.                 SendMessage(SpiffParam,keyKeyPressCharacter);
  1513.             }
  1514.     }
  1515.  
  1516.  
  1517. void                CMyDocument::DoSkipToNext(void)
  1518.     {
  1519.         if (Playing != -1)
  1520.             {
  1521.                 if (Randomize)
  1522.                     {
  1523.                         StartRandomSong();
  1524.                     }
  1525.                  else
  1526.                     {
  1527.                         if (Playing < ListOfSongs->GetNumElements() - 1)
  1528.                             {
  1529.                                 StartThisSong(Playing + 1);
  1530.                             }
  1531.                          else
  1532.                             {
  1533.                                 StartThisSong(0);
  1534.                             }
  1535.                     }
  1536.             }
  1537.     }
  1538.  
  1539.  
  1540. void                CMyDocument::DoVolumeUp(void)
  1541.     {
  1542.         if ((Playing != -1) && PlayerExists)
  1543.             {
  1544.                 SendMessage('+',keyKeyPressCharacter);
  1545.             }
  1546.     }
  1547.  
  1548.  
  1549. void                CMyDocument::DoVolumeDown(void)
  1550.     {
  1551.         if ((Playing != -1) && PlayerExists)
  1552.             {
  1553.                 SendMessage('-',keyKeyPressCharacter);
  1554.             }
  1555.     }
  1556.  
  1557.  
  1558. void                CMyDocument::DoIdle(long Stupid)
  1559.     {
  1560.         CPauseButton*                    PauseButton;
  1561.         short                                    Error;
  1562.         AppleEvent                        Event;
  1563.         AEAddressDesc                    AddressDescriptor;
  1564.         AEDesc                                FileList;
  1565.         SongRec                                TheSong;
  1566.         AEDesc                                AEFileDescriptor;
  1567.         short                                    ShortInt;
  1568.         long                                    LongInt;
  1569.         Boolean                                BooleanValue;
  1570.         AEDesc                                TempDesc;
  1571.         AEDesc                                ListElement;
  1572.         long                                    OldPlayer;
  1573.         ProcessSerialNumber        OurPSN;
  1574.         PString                                NewWindowName;
  1575.         Handle                                String1,String2,String3;
  1576.  
  1577.         StackSizeTest();
  1578.         if ((!PlayerExists) && (SongToStart != -1))
  1579.             {
  1580.                 PlayerState = PlayerLaunching;
  1581.                 ListOfSongs->GetElement(SongToStart,&TheSong);
  1582.                 if (TheSong.Tracker)
  1583.                     {
  1584.                         Application->LaunchTracker(FRANKSEIDECREATOR);
  1585.                     }
  1586.                  else
  1587.                     {
  1588.                         Application->LaunchTracker(TRACKERSERVERCREATOR);
  1589.                     }
  1590.             }
  1591.         if (PlayerExists && (PlayerState == PlayerWaitingForInit))
  1592.             {
  1593.                 short                    BitTemp;
  1594.  
  1595.  
  1596.                 DeregisterIdler(this);
  1597.  
  1598.                 PlayerState = PlayerRunning;
  1599.                 OldPlayer = Playing;
  1600.                 Playing = SongToStart;
  1601.                 SongToStart = -1;
  1602.                 SongList->Redraw(OldPlayer,OldPlayer);
  1603.                 SongList->Redraw(Playing,Playing);
  1604.  
  1605.                 ListOfSongs->GetElement(Playing,&TheSong);
  1606.                 CheckHeap();
  1607.  
  1608.                 BeginStringOperation();
  1609.                 String1 = PString2Handle(TheFile.name);
  1610.                 RegisterString(String1);
  1611.                 String2 = GetCString(SeparatorID);
  1612.                 RegisterString(String2);
  1613.                 String3 = PString2Handle(TheSong.SongName);
  1614.                 RegisterString(String3);
  1615.                 String1 = ConStr(String1,String2);
  1616.                 String1 = ConStr(String1,String3);
  1617.                 EndStringOperation(String1);
  1618.                 Handle2PString(String1,NewWindowName);
  1619.                 ReleaseHandle(String1);
  1620.                 SetWTitle(RootWindow->MyGrafPtr,NewWindowName);
  1621.  
  1622.                 /* constructing nasty parameter block & sending open event to tracker */
  1623.                 HLock((Handle)this);
  1624.  
  1625.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  1626.                     sizeof(ProcessSerialNumber),&AddressDescriptor);
  1627.  
  1628.                 Error = AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&AddressDescriptor,
  1629.                     kAutoGenerateReturnID,kAnyTransactionID,&Event);
  1630.                 CheckHeap();
  1631.  
  1632.                 Error = AECreateList(NIL,0,False,&FileList);
  1633.                 HLock((Handle)TheSong.SongLocation);
  1634.                 AECreateDesc(typeAlias,(void*)*TheSong.SongLocation,
  1635.                     HandleSize((Handle)TheSong.SongLocation),&ListElement);
  1636.                 HUnlock((Handle)TheSong.SongLocation);
  1637.                 Error = AEPutDesc(&FileList,0,&ListElement);
  1638.                 Error = AEDisposeDesc(&ListElement);
  1639.                 Error = AEPutParamDesc(&Event,keyDirectObject,&FileList);
  1640.                 Error = AEDisposeDesc(&FileList);
  1641.  
  1642.                 if (TheSong.AntiAliasingOverrideDefault)
  1643.                     {
  1644.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.AntiAliasing,
  1645.                             sizeof(MyBoolean),&TempDesc);
  1646.                     }
  1647.                  else
  1648.                     {
  1649.                         Error = AECreateDesc(typeShortInteger,(void*)&AntiAliasing,
  1650.                             sizeof(MyBoolean),&TempDesc);
  1651.                     }
  1652.                 Error = AEPutParamDesc(&Event,keyAntiAliasing,&TempDesc);
  1653.                 Error = AEDisposeDesc(&TempDesc);
  1654.  
  1655.                 if (TheSong.StereoOnOverrideDefault)
  1656.                     {
  1657.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoOn,
  1658.                             sizeof(MyBoolean),&TempDesc);
  1659.                     }
  1660.                  else
  1661.                     {
  1662.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoOn,
  1663.                             sizeof(MyBoolean),&TempDesc);
  1664.                     }
  1665.                 Error = AEPutParamDesc(&Event,keyStereoOn,&TempDesc);
  1666.                 Error = AEDisposeDesc(&TempDesc);
  1667.  
  1668.                 if (TheSong.SamplingRateOverrideDefault)
  1669.                     {
  1670.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.SamplingRate,
  1671.                             sizeof(ushort),&TempDesc);
  1672.                     }
  1673.                  else
  1674.                     {
  1675.                         Error = AECreateDesc(typeShortInteger,(void*)&SamplingRate,
  1676.                             sizeof(ushort),&TempDesc);
  1677.                     }
  1678.                 Error = AEPutParamDesc(&Event,keySamplingRate,&TempDesc);
  1679.                 Error = AEDisposeDesc(&TempDesc);
  1680.  
  1681.                 if (TheSong.NumRepeatsOverrideDefault)
  1682.                     {
  1683.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.NumRepeats,
  1684.                             sizeof(short),&TempDesc);
  1685.                     }
  1686.                  else
  1687.                     {
  1688.                         Error = AECreateDesc(typeShortInteger,(void*)&NumRepeats,
  1689.                             sizeof(short),&TempDesc);
  1690.                     }
  1691.                 Error = AEPutParamDesc(&Event,keyNumRepeats,&TempDesc);
  1692.                 Error = AEDisposeDesc(&TempDesc);
  1693.  
  1694.                 if (TheSong.SpeedOverrideDefault)
  1695.                     {
  1696.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Speed,
  1697.                             sizeof(short),&TempDesc);
  1698.                     }
  1699.                  else
  1700.                     {
  1701.                         Error = AECreateDesc(typeShortInteger,(void*)&Speed,
  1702.                             sizeof(short),&TempDesc);
  1703.                     }
  1704.                 Error = AEPutParamDesc(&Event,keySpeed,&TempDesc);
  1705.                 Error = AEDisposeDesc(&TempDesc);
  1706.  
  1707.                 if (TheSong.StereoMixOverrideDefault)
  1708.                     {
  1709.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoMix,
  1710.                             sizeof(short),&TempDesc);
  1711.                     }
  1712.                  else
  1713.                     {
  1714.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoMix,
  1715.                             sizeof(short),&TempDesc);
  1716.                     }
  1717.                 Error = AEPutParamDesc(&Event,keyStereoMix,&TempDesc);
  1718.                 Error = AEDisposeDesc(&TempDesc);
  1719.  
  1720.                 if (TheSong.VolumeOverrideDefault)
  1721.                     {
  1722.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Volume,
  1723.                             sizeof(short),&TempDesc);
  1724.                     }
  1725.                  else
  1726.                     {
  1727.                         Error = AECreateDesc(typeShortInteger,(void*)&Volume,
  1728.                             sizeof(short),&TempDesc);
  1729.                     }
  1730.                 Error = AEPutParamDesc(&Event,keyLoudness,&TempDesc);
  1731.                 Error = AEDisposeDesc(&TempDesc);
  1732.  
  1733.                 if (UseSixteenBitMode)
  1734.                     {
  1735.                         BitTemp = 16;
  1736.                     }
  1737.                  else
  1738.                     {
  1739.                         BitTemp = 8;
  1740.                     }
  1741.                 Error = AECreateDesc(typeShortInteger,(void*)&BitTemp,
  1742.                     sizeof(short),&TempDesc);
  1743.                 Error = AEPutParamDesc(&Event,keyNumBits,&TempDesc);
  1744.                 Error = AEDisposeDesc(&TempDesc);
  1745.  
  1746.                 Error = GetCurrentProcess(&OurPSN);
  1747.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPSN,
  1748.                     sizeof(ProcessSerialNumber),&TempDesc);
  1749.                 Error = AEPutParamDesc(&Event,keySenderPSN,&TempDesc);
  1750.                 Error = AEDisposeDesc(&TempDesc);
  1751.  
  1752.                 Application->SendMessage(OurPlayer,&Event);
  1753.                 Error = AEDisposeDesc(&AddressDescriptor);
  1754.                 Error = AEDisposeDesc(&Event);
  1755.                 HUnlock((Handle)this);
  1756.  
  1757.                 if (PausePlayButton != NIL)
  1758.                     {
  1759.                         delete PausePlayButton;
  1760.                     }
  1761.                 PauseButton = new CPauseButton;
  1762.                 PausePlayButton = PauseButton;
  1763.                 PauseButton->IPauseButton(this,RootWindow);
  1764.                 if (!RootWindow->Suspended)
  1765.                     {
  1766.                         PauseButton->DoResume();
  1767.                     }
  1768.                 PauseButton->DoUpdate();
  1769.  
  1770.                 StopButton->DoEnable();
  1771.                 RewindButton->DoEnable();
  1772.                 FastForwardButton->DoEnable();
  1773.                 SkipToNextButton->DoEnable();
  1774.             }
  1775.     }
  1776.  
  1777.  
  1778. void                CMyDocument::PlayerDiedNotification(void)
  1779.     {
  1780.         CPlayButton*        PlayButton;
  1781.         long                        OldPlayer;
  1782.  
  1783.         PlayerExists = False;
  1784.         OldPlayer = Playing;
  1785.         Playing = -1;
  1786.         HLock((Handle)this);
  1787.         SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  1788.         HUnlock((Handle)this);
  1789.         SongList->Redraw(OldPlayer,OldPlayer);
  1790.         if (PlayNextWhenThisOneStops)
  1791.             {
  1792.                 if (SongToStart == -1)
  1793.                     {
  1794.                         /* we want to hear the "next" song, but one was not specified. */
  1795.                         if (Randomize)
  1796.                             {
  1797.                                 StartRandomSong();
  1798.                             }
  1799.                          else
  1800.                             {
  1801.                                 if (OldPlayer < ListOfSongs->GetNumElements() - 1)
  1802.                                     {
  1803.                                         StartThisSong(OldPlayer + 1);
  1804.                                     }
  1805.                                  else
  1806.                                     {
  1807.                                         if (Repeat)
  1808.                                             {
  1809.                                                 StartThisSong(0);
  1810.                                             }
  1811.                                          else
  1812.                                             {
  1813.                                                 PlayNextWhenThisOneStops = False;
  1814.                                             }
  1815.                                     }
  1816.                             }
  1817.                     }
  1818.                  else
  1819.                     {
  1820.                         /* they DID specify which song to listen to next */
  1821.                         StartThisSong(SongToStart);
  1822.                     }
  1823.             }
  1824.  
  1825.         delete PausePlayButton;
  1826.         PlayButton = new CPlayButton;
  1827.         PlayButton->IPlayButton(this,RootWindow);
  1828.         PausePlayButton = PlayButton;
  1829.         if (!RootWindow->Suspended)
  1830.             {
  1831.                 PlayButton->DoResume();
  1832.             }
  1833.         PlayButton->DoUpdate();
  1834.  
  1835.         StopButton->DoDisable();
  1836.         RewindButton->DoDisable();
  1837.         FastForwardButton->DoDisable();
  1838.         SkipToNextButton->DoDisable();
  1839.     }
  1840.  
  1841.  
  1842. void                CMyDocument::PlayerLaunchedNotification(ProcessSerialNumber TheProcNum)
  1843.     {
  1844.         StackSizeTest();
  1845.         PlayerExists = True;
  1846.         PlayerState = PlayerWaitingForInit;
  1847.         OurPlayer = TheProcNum;
  1848.     }
  1849.  
  1850.  
  1851. void                CMyDocument::SetNewSelection(long NewSelection)
  1852.     {
  1853.         SpecificSamplingRateBox->StoreValue();
  1854.         SpecificStereoMixBox->StoreValue();
  1855.         SpecificNumRepeatsBox->StoreValue();
  1856.         SpecificSpeedBox->StoreValue();
  1857.         SpecificVolumeBox->StoreValue();
  1858.         DefaultSamplingRateBox->StoreValue();
  1859.         DefaultStereoMixBox->StoreValue();
  1860.         DefaultNumRepeatsBox->StoreValue();
  1861.         DefaultSpeedBox->StoreValue();
  1862.         DefaultVolumeBox->StoreValue();
  1863.         if (Selection != -1)
  1864.             {
  1865.                 long            SelectionTemp;
  1866.  
  1867.                 SelectionTemp = Selection;
  1868.                 Selection = -1;
  1869.                 SongList->Redraw(SelectionTemp,SelectionTemp);
  1870.             }
  1871.         Selection = NewSelection;
  1872.         if (NewSelection == -1)
  1873.             {
  1874.                 CStaticText*        StaticText;
  1875.                 LongPoint                Start,Extent;
  1876.  
  1877.                 SpecificStereoOnBox->DoDisable();
  1878.                 SpecificAntiAliasingBox->DoDisable();
  1879.                 SpecificSamplingRateBox->DoDisable();
  1880.                 SpecificStereoMixBox->DoDisable();
  1881.                 SpecificNumRepeatsBox->DoDisable();
  1882.                 SpecificSpeedBox->DoDisable();
  1883.                 SpecificVolumeBox->DoDisable();
  1884.                 SpecificTrackerBox->DoDisable();
  1885.                 SpecificSamplingRateText->DoDisable();
  1886.                 SpecificStereoMixText->DoDisable();
  1887.                 SpecificNumRepeatsText->DoDisable();
  1888.                 SpecificSpeedText->DoDisable();
  1889.                 SpecificVolumeText->DoDisable();
  1890.                 OverrideStereoOnBox->DoDisable();
  1891.                 OverrideAntiAliasingBox->DoDisable();
  1892.                 OverrideSamplingRateBox->DoDisable();
  1893.                 OverrideStereoMixBox->DoDisable();
  1894.                 OverrideNumRepeatsBox->DoDisable();
  1895.                 OverrideSpeedBox->DoDisable();
  1896.                 OverrideVolumeBox->DoDisable();
  1897.             }
  1898.          else
  1899.             {
  1900.                 LongPoint            Start,Extent;
  1901.                 Handle                String1;
  1902.                 Handle                String2;
  1903.                 Handle                String3;
  1904.                 Handle                String4;
  1905.                 SongRec                TheSong;
  1906.                 CPauseButton*    PauseButton;
  1907.                 CStaticText*    StaticText;
  1908.  
  1909.                 StackSizeTest();
  1910.                 SongList->Redraw(NewSelection,NewSelection);
  1911.                 ListOfSongs->GetElement(NewSelection,&TheSong);
  1912.  
  1913.                 OverrideStereoOnBox->DoEnable();
  1914.                 if (OverrideStereoOnBox->State != TheSong.StereoOnOverrideDefault)
  1915.                     {
  1916.                         OverrideStereoOnBox->DoThang();
  1917.                     }
  1918.                 if (TheSong.StereoOnOverrideDefault)
  1919.                     {
  1920.                         SpecificStereoOnBox->DoEnable();
  1921.                         if (SpecificStereoOnBox->State != TheSong.StereoOn)
  1922.                             {
  1923.                                 SpecificStereoOnBox->DoThang();
  1924.                             }
  1925.                     }
  1926.                  else
  1927.                     {
  1928.                         SpecificStereoOnBox->DoDisable();
  1929.                     }
  1930.  
  1931.                 OverrideAntiAliasingBox->DoEnable();
  1932.                 if (OverrideAntiAliasingBox->State != TheSong.AntiAliasingOverrideDefault)
  1933.                     {
  1934.                         OverrideAntiAliasingBox->DoThang();
  1935.                     }
  1936.                 if (TheSong.AntiAliasingOverrideDefault)
  1937.                     {
  1938.                         SpecificAntiAliasingBox->DoEnable();
  1939.                         if (SpecificAntiAliasingBox->State != TheSong.AntiAliasing)
  1940.                             {
  1941.                                 SpecificAntiAliasingBox->DoThang();
  1942.                             }
  1943.                     }
  1944.                  else
  1945.                     {
  1946.                         SpecificAntiAliasingBox->DoDisable();
  1947.                     }
  1948.  
  1949.                 OverrideSamplingRateBox->DoEnable();
  1950.                 if (OverrideSamplingRateBox->State != TheSong.SamplingRateOverrideDefault)
  1951.                     {
  1952.                         OverrideSamplingRateBox->DoThang();
  1953.                     }
  1954.                 if (TheSong.SamplingRateOverrideDefault)
  1955.                     {
  1956.                         SpecificSamplingRateBox->DoEnable();
  1957.                         SpecificSamplingRateText->DoEnable();
  1958.                         SpecificSamplingRateBox->SetValue(TheSong.SamplingRate);
  1959.                     }
  1960.                  else
  1961.                     {
  1962.                         SpecificSamplingRateBox->DoDisable();
  1963.                         SpecificSamplingRateText->DoDisable();
  1964.                     }
  1965.  
  1966.                 OverrideStereoMixBox->DoEnable();
  1967.                 if (OverrideStereoMixBox->State != TheSong.StereoMixOverrideDefault)
  1968.                     {
  1969.                         OverrideStereoMixBox->DoThang();
  1970.                     }
  1971.                 if (TheSong.StereoMixOverrideDefault)
  1972.                     {
  1973.                         SpecificStereoMixBox->DoEnable();
  1974.                         SpecificStereoMixText->DoEnable();
  1975.                         SpecificStereoMixBox->SetValue(TheSong.StereoMix);
  1976.                     }
  1977.                  else
  1978.                     {
  1979.                         SpecificStereoMixBox->DoDisable();
  1980.                         SpecificStereoMixText->DoDisable();
  1981.                     }
  1982.  
  1983.                 OverrideNumRepeatsBox->DoEnable();
  1984.                 if (OverrideNumRepeatsBox->State != TheSong.NumRepeatsOverrideDefault)
  1985.                     {
  1986.                         OverrideNumRepeatsBox->DoThang();
  1987.                     }
  1988.                 if (TheSong.NumRepeatsOverrideDefault)
  1989.                     {
  1990.                         SpecificNumRepeatsBox->DoEnable();
  1991.                         SpecificNumRepeatsText->DoEnable();
  1992.                         SpecificNumRepeatsBox->SetValue(TheSong.NumRepeats);
  1993.                     }
  1994.                  else
  1995.                     {
  1996.                         SpecificNumRepeatsBox->DoDisable();
  1997.                         SpecificNumRepeatsText->DoDisable();
  1998.                     }
  1999.  
  2000.                 OverrideSpeedBox->DoEnable();
  2001.                 if (OverrideSpeedBox->State != TheSong.SpeedOverrideDefault)
  2002.                     {
  2003.                         OverrideSpeedBox->DoThang();
  2004.                     }
  2005.                 if (TheSong.SpeedOverrideDefault)
  2006.                     {
  2007.                         SpecificSpeedBox->DoEnable();
  2008.                         SpecificSpeedText->DoEnable();
  2009.                         SpecificSpeedBox->SetValue(TheSong.Speed);
  2010.                     }
  2011.                  else
  2012.                     {
  2013.                         SpecificSpeedBox->DoDisable();
  2014.                         SpecificSpeedText->DoDisable();
  2015.                     }
  2016.  
  2017.                 OverrideVolumeBox->DoEnable();
  2018.                 if (OverrideVolumeBox->State != TheSong.VolumeOverrideDefault)
  2019.                     {
  2020.                         OverrideVolumeBox->DoThang();
  2021.                     }
  2022.                 if (TheSong.VolumeOverrideDefault)
  2023.                     {
  2024.                         SpecificVolumeBox->DoEnable();
  2025.                         SpecificVolumeText->DoEnable();
  2026.                         SpecificVolumeBox->SetValue(TheSong.Volume);
  2027.                     }
  2028.                  else
  2029.                     {
  2030.                         SpecificVolumeBox->DoDisable();
  2031.                         SpecificVolumeText->DoDisable();
  2032.                     }
  2033.  
  2034.                 SpecificTrackerBox->DoEnable();
  2035.                 if (SpecificTrackerBox->State != TheSong.Tracker)
  2036.                     {
  2037.                         SpecificTrackerBox->DoThang();
  2038.                     }
  2039.             }
  2040.     }
  2041.  
  2042.  
  2043. void                CMyDocument::MoveSong(long SongIndex, long NewIndex)
  2044.     {
  2045.         SongRec            MySong;
  2046.         long                OldSelection;
  2047.         long                Temp;
  2048.  
  2049.         UpToDate = False;
  2050.         SpecificSamplingRateBox->StoreValue();
  2051.         SpecificStereoMixBox->StoreValue();
  2052.         SpecificNumRepeatsBox->StoreValue();
  2053.         SpecificSpeedBox->StoreValue();
  2054.         SpecificVolumeBox->StoreValue();
  2055.         DefaultSamplingRateBox->StoreValue();
  2056.         DefaultStereoMixBox->StoreValue();
  2057.         DefaultNumRepeatsBox->StoreValue();
  2058.         DefaultSpeedBox->StoreValue();
  2059.         DefaultVolumeBox->StoreValue();
  2060.  
  2061.         OldSelection = Playing;
  2062.         Playing = -1;
  2063.         SongList->Redraw(OldSelection,OldSelection);
  2064.         Playing = OldSelection;
  2065.         if (Playing == SongIndex)
  2066.             {
  2067.                 Playing = NewIndex;
  2068.                 if (NewIndex > SongIndex)
  2069.                     {
  2070.                         Playing -= 1;
  2071.                     }
  2072.             }
  2073.          else
  2074.             {
  2075.                 if (SongIndex < NewIndex)
  2076.                     {
  2077.                         if ((Playing > SongIndex) && (Playing < NewIndex))
  2078.                             {
  2079.                                 Playing -= 1;
  2080.                             }
  2081.                     }
  2082.                  else
  2083.                     {
  2084.                         if ((Playing >= NewIndex) && (Playing < SongIndex))
  2085.                             {
  2086.                                 Playing += 1;
  2087.                             }
  2088.                     }
  2089.             }
  2090.         SongList->Redraw(Playing,Playing);
  2091.  
  2092.         OldSelection = Selection;
  2093.         Selection = -1;
  2094.         SongList->Redraw(OldSelection,OldSelection);
  2095.         if ((SongIndex < 0) || (SongIndex >= ListOfSongs->GetNumElements()))
  2096.             {
  2097.                 return;
  2098.             }
  2099.         if (NewIndex < 0)
  2100.             {
  2101.                 NewIndex = 0;
  2102.             }
  2103.         ListOfSongs->GetElement(SongIndex,&MySong);
  2104.         ListOfSongs->DeleteElement(SongIndex);
  2105.         if (NewIndex > SongIndex)
  2106.             {
  2107.                 NewIndex -= 1;
  2108.             }
  2109.         NewIndex = ListOfSongs->InsertElement(NewIndex);
  2110.         ListOfSongs->PutElement(NewIndex,&MySong);
  2111.         Selection = NewIndex;
  2112.         if (SongIndex > NewIndex)
  2113.             {
  2114.                 Temp = SongIndex;
  2115.                 SongIndex = NewIndex;
  2116.                 NewIndex = Temp;
  2117.             }
  2118.         SongList->Redraw(SongIndex,NewIndex);
  2119.     }
  2120.  
  2121.  
  2122. void                CMyDocument::ResetRandomPlayList(void)
  2123.     {
  2124.         long                Scan;
  2125.         long                End;
  2126.         SongRec            Temp;
  2127.  
  2128.         End = ListOfSongs->GetNumElements();
  2129.         for (Scan = 0; Scan < End; Scan += 1)
  2130.             {
  2131.                 ListOfSongs->GetElement(Scan,&Temp);
  2132.                 Temp.PlayedFlag = False;
  2133.                 ListOfSongs->PutElement(Scan,&Temp);
  2134.             }
  2135.     }
  2136.  
  2137.  
  2138. void                CMyDocument::StartRandomSong(void)
  2139.     {
  2140.         short                RunoutCount;
  2141.         long                Possibility;
  2142.         long                NumSongs;
  2143.         SongRec            Temp;
  2144.         long                StartingPoint;
  2145.  
  2146.         /* randomly look for a song that hasn't been played.  If we */
  2147.         /* can't find one then do a linear search for one.  If we fail that */
  2148.         /* then there are no more: reset and play if <repeat> is on, otherwise */
  2149.         /* just stop. */
  2150.         CancelCurrentSong();
  2151.      TryAgainPoint:
  2152.         NumSongs = ListOfSongs->GetNumElements();
  2153.         if (NumSongs == 0)
  2154.             {
  2155.                 return; /* oops, can't play anything */
  2156.             }
  2157.         RunoutCount = MAXRANDOMTRIESBEFOREGIVINGUP;
  2158.         while (RunoutCount > 0)
  2159.             {
  2160.                 Possibility = ((unsigned short)Random()) % NumSongs;
  2161.                 ListOfSongs->GetElement(Possibility,&Temp);
  2162.                 if (!Temp.PlayedFlag)
  2163.                     {
  2164.                         /* found one to play */
  2165.                      FoundOnePoint:
  2166.                         StartThisSong(Possibility);
  2167.                         return;
  2168.                     }
  2169.                 RunoutCount -= 1;
  2170.             }
  2171.         /* failed random search.  Do linear search */
  2172.         StartingPoint = Possibility;
  2173.         do
  2174.             {
  2175.                 Possibility += 1;
  2176.                 if (Possibility >= NumSongs)
  2177.                     {
  2178.                         Possibility = 0;
  2179.                     }
  2180.                 ListOfSongs->GetElement(Possibility,&Temp);
  2181.                 if (!Temp.PlayedFlag)
  2182.                     {
  2183.                         goto FoundOnePoint;
  2184.                     }
  2185.             } while (Possibility != StartingPoint);
  2186.         /* failed that!  Reset and try again. */
  2187.         if (Repeat)
  2188.             {
  2189.                 /* there is no possible way to get into an infinite loop. */
  2190.                 ResetRandomPlayList();
  2191.                 goto TryAgainPoint;
  2192.             }
  2193.     }
  2194.  
  2195.  
  2196. /* this sends control events to the remote player.  Note that it only */
  2197. /* supports short integer messages, but that's ok because they're all shorts */
  2198. void                CMyDocument::SendMessage(short TheMessage, DescType TheKeyWord)
  2199.     {
  2200.         short                        Error;
  2201.         AppleEvent            Event;
  2202.         AEAddressDesc        AddressDescriptor;
  2203.         short                        KeyPress;
  2204.  
  2205.         HLock((Handle)this); /* make sure the OurPlayer variable doesn't move */
  2206.         Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  2207.             sizeof(ProcessSerialNumber),&AddressDescriptor);
  2208.         HUnlock((Handle)this);
  2209.         Error = AECreateAppleEvent(ControlEventClass,ControlEvent,&AddressDescriptor,
  2210.             kAutoGenerateReturnID,kAnyTransactionID,&Event);
  2211.         Error = AEPutParamPtr(&Event,TheKeyWord,typeShortInteger,
  2212.             (void*)&TheMessage,sizeof(short));
  2213.         Application->SendMessage(OurPlayer,&Event);
  2214.         Error = AEDisposeDesc(&AddressDescriptor);
  2215.         Error = AEDisposeDesc(&Event);
  2216.         HUnlock((Handle)this);
  2217.     }
  2218.